home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Periodicals / develop / develop 2 code / Secret Life of Mem. Mgr. / UGlobals.p < prev    next >
Encoding:
Text File  |  1990-01-31  |  6.0 KB  |  139 lines  |  [TEXT/MPS ]

  1. unit UGlobals;
  2. {$S Main}
  3.  
  4. (* Global constants,  types, typos, and variables for the HeapDemo application  *)
  5. (* Written by Richard Clark (AppleLink, Delphi, GEnie, MCI, MouseHole: RDCLARK *)
  6. (*                                   Internet: rdclark@apple.com or rdclark@applelink.apple.com) *)
  7. (* Copyright (c) 1989 by Apple Computer, Inc. All Rights Reserved                       *)
  8.  
  9. (* The program works by allocating a 16K block (Well, 16K + something) in the Application *)
  10. (* Heap, then initializing this block as another Heap Zone. The user is allowed to allocate      *)
  11. (* relocatable and non-relocatable blocks (Handles and Pointers) in this mini-heap, in 1K     *)
  12. (* increments. The handles and pointers which refer to these blocks are stored in an array, *)
  13. (* and this information is used to draw a diagram of the heap on the screen. The heap is       *)
  14. (* shown in both its "before" and "after" states.                                                    *)
  15.  
  16. (* This program should work on _any_ Macintosh, from the Lisa running MacWorks, to the  *)
  17. (* Macintosh N, where n >= 2 (I hope!).                                                            *)
  18.  
  19. interface
  20.  
  21.     USES
  22.         Types, Memory, Menus, Dialogs;
  23.         
  24.     const
  25.      (* Menu definitions: mXXX are MENU IDs, ixYYYY are items within a given menu *)
  26.         mApple = 1000;
  27.         iaAbout = 1;
  28.  
  29.         mFile = 1001;
  30.         ifOpen = 1;
  31.         ifClose = 2;
  32.         ifQuit = 4;
  33.  
  34.         mEdit = 1002;
  35.         ieUndo = 1;
  36.         ieCut = 3;
  37.         ieCopy = 4;
  38.         iePaste = 5;
  39.         ieClear = 6;
  40.  
  41.         mWindow = 1003;
  42.         imSimpleDialog = 1;
  43.         imComplexDialog = 2;
  44.         imShowLegend = 4;
  45.  
  46.         mSpecial = 1004;
  47.         isEraseHeap = 1;
  48.  
  49.     (* Dialog Resource IDs *)
  50.         dAbout = 1000;
  51.         dShortMemory = 1001;
  52.         dExtendedMemory = 1002;
  53.  
  54.     (* Window resourse IDs *)
  55.         wLegend = 1000;
  56.  
  57.     (* Alert resource IDs *)
  58.         aNoOldHeap = 1000;         (* The "look but don't touch" dialog *)
  59.         aBadNumber = 1001;        (* The user entered an incorrect memory value *)
  60.         aNoDemoMemory = 1002; (* We couldn't allocate memory in the demo heap *)
  61.         aNoMoreBlocks = 1003;    (* We're at our block limit *)
  62.         aConfirmErase = 1004;    (* Really erase the heap? *)
  63.  
  64.      (* Window reference constants *)
  65.         MemDialogRefCon = 1;
  66.         LegendRefCon = 2;
  67.  
  68.     (* Other program-specific constants *)
  69.         MyHeapSize = 16;            (* Display a 16K Heap *)
  70.         MyArraySize = 17;          (* The number of cells alotted to each "Heap" array. This includes 1 *)
  71.                                   (* "extra" cell so that you can fill up the heap and still be able to try and *)
  72.                                     (* get another block. (Think of the situation where the heap is full, and you *)
  73.                                   (* have one or more of the blocks marked as purgeable. In that case, you *)
  74.                                   (* _could_ allocate another block, so you'll need an array element to hold *)
  75.                                   (* it. The array element of the purged block will be reclaimed automatically leter *)
  76.         HeapBias = 316;               (* 52 bytes for the header, plus 264 bytes for a Master Pointer Block *)
  77.         HeapTrailer = 12;            (* The heap is followed by a 12-byte trailer *)
  78.         Slop = 0;                         (* Allocate an extra 0 bytes of "slop" on our heap *)
  79.         BlockHeaderSize = 8;       (* This much is removed from each block allocation so that the physical size matches *)
  80.                                    (* the requested size *)
  81.  
  82.      (* Block type constants for our "blocks" array *)
  83.         blkFree = 0;                  (* available for use *)
  84.         blkPointer = 1;              (* this is a pointer *)
  85.         blkHandle = 2;              (* This is a Handle *)
  86.         blkMaster = 3;              (* This is a Master Pointer Block (this constant not used in this release) *)
  87.  
  88.     type
  89.         BlockInfo = record
  90.                 blkType: integer;       (* free, pointer, or handle *)
  91.                 blkSource: Ptr;            (* This is the pointer or handle to the block*)
  92.                 blkStart: LONGINT;      (* the block's current starting address *)
  93.                 blkOldStart: LONGINT; (* the block's previous starting address *)
  94.                 blkSize: LONGINT;        (* The length of this block (in bytes) *)
  95.                 blkSequence: INTEGER; (* A unique ID # *)
  96.                 blkPurgeable: Boolean; (* Purgeable and Locked attributes *)
  97.                 blkLocked: Boolean;
  98.                 blkDirty: Boolean;          (* This tells us if the block has been changed *)
  99.             end; (* BlockInfo *)
  100.  
  101.         HeapInfo = record
  102.                 blocks: array[1..MyArraySize] of BlockInfo;
  103.                 numBlocks: INTEGER;                (* the total number of blocks ever allocated  *)
  104.                                              (* ( even if they get deallocated later ) *)
  105.                 blocksUsed: INTEGER;                (* the current number of blocks allocated at this moment*)
  106.                 selectedBlock: INTEGER;            (* The array index of the currently selected block *)
  107.                 maxFreeBytes: LONGINT;         (* How many bytes are free *)
  108.                 maxBlocks: INTEGER;               (* What's the size of the largest available block (in K) *)
  109.                 maxAvailBytes: LONGINT;        (* What's the size of the largest available block (in blocks) *)
  110.                 maxAfterCompact: LONGINT;    (* What's the largest block after compaction?? *)
  111.                 maxAfterPurge: LONGINT;       (* What's the largest contiguous space after a purge?? *)
  112.                 heapRect: Rect;                       (* Our heap display's bounding rectangle *)
  113.             end;
  114.  
  115.  
  116.     var
  117.         system: record                        (* Information about the machine *)
  118.                 EnhancedROMs: Boolean;            (* Do we have 128K ROMs (or later)? *)
  119.                 HasWNE: Boolean;                (* Is WaitNextEvent implemented? *)
  120.                 HasStyledTE: Boolean;            (* Do we have Styled TextEdit (for the about box?) *)
  121.             end;
  122.  
  123.         application: record                    (* User preferences (determined by a'pref 1000' resource *)
  124.                 UseExtendedDialog: Boolean;    (* Start up with the "Advanced" dialog? (put $FFFF into *)
  125.                                             (* 'pref' 1000 to enable this.                                *)
  126.             end;
  127.         MyAppZone, MyDemoZone: THz;    (* My Application and "demo" heaps *)
  128.         theMiniHeap: Ptr;                    (* a pointer to the start of the Demo heap *)
  129.         OldHeap, CurrHeap: HeapInfo;        (* The current and past heap info arrays *)
  130.         BytesPerPixel: LONGINT;            (* How many bytes does one line (pixel) on the display represent? *)
  131.         MemoryDialog: DialogPtr;            (* A pointer to my (one and only) display. *)
  132.                                             (* Sorry guys, I'm using the Dialog Mangler. Kids: don't try this aty home! *)
  133.         AppleMenu, FileMenu: MenuHandle; (* Can you handle this? *)
  134.         EditMenu, WindowMenu: MenuHandle;
  135.         SpecialMenu: MenuHandle;
  136.         Quit: Boolean;
  137.  
  138. implementation
  139. end.